﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using MasterDetailTemplate.Models;
using MasterDetailTemplate.Services;
using MvvmHelpers.Commands;

namespace MasterDetailTemplate.ViewModels {
    /// <summary>
    /// 纪念日详情页
    /// </summary>
    public class AnniversaryDetailPageViewModel : ViewModelBase {

        private IEventStorage _eventStorage;
        public AnniversaryDetailPageViewModel(IEventStorage eventStorage,
            IContentNavigationService contentNavigationService) {
            _eventStorage = eventStorage;
            _contentNavigationService = contentNavigationService;
        }

        private IContentNavigationService _contentNavigationService;

        private Event _event;

        public Event Event {
            get => _event;
            set => Set(nameof(Event), ref _event, value);
        }

        public bool IsImportant
        {
            get => _isImportant;
            set => Set(nameof(IsImportant), ref _isImportant, value);
        }

        private bool _isImportant;

        public string Att
        {
            get => _att;
            set => Set(nameof(Att), ref _att, value);
        }

        private string _att;

        public RelayCommand PageAppearingCommand =>
            _pageAppearingCommand ?? (_pageAppearingCommand = new RelayCommand(
                async () =>
                {
                    Event = await _eventStorage.GetEventAsync(Event.Id);
                    Att = Event.Attribute.Equals(1) ? "纪念日" : "倒数日";
                    IsImportant = Event.IsImportant.Equals(1) ? true : false;
                }));

        private RelayCommand _pageAppearingCommand;

        public RelayCommand EventChangeCommand =>
            _eventChangeCommand ?? (_eventChangeCommand =
                new RelayCommand(async () =>
                    await EventChangeCommandFunction()));

        private RelayCommand _eventChangeCommand;

        public async Task EventChangeCommandFunction() =>
            await _contentNavigationService.NavigateToAsync(
                ContentNavigationConstants.AnniversaryChangePage, Event);

    }
}